import javax.servlet.http.*;
import java.sql.*;
import java.io.*;

public class CollegeLoginServlet extends HttpServlet
{
  
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException
  {

     try
       {

        String college_uname=request.getParameter("college_uname");
        String college_pwd=request.getParameter("college_pwd");
         String str1="";
        String str="";
        String college_name="";
        String college_code="";
        response.setContentType("text/html");
        PrintWriter out=response.getWriter();


        Class.forName("oracle.jdbc.driver.OracleDriver");
       Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","pac","mca"); 

       Statement stmt=con.createStatement();
         

       ResultSet rs = stmt.executeQuery("SELECT *FROM college_login WHERE college_uname='"+college_uname+"' and college_pwd='"+college_pwd+"'");


         if(rs.next())

         {
           
         ResultSet rs2=stmt.executeQuery("SELECT *FROM college_register WHERE  college_uname='" +college_uname+ "'");
 
    while(rs2.next())
     {
              college_name = rs2.getString(1);
             String university = rs2.getString(2);
              college_code = rs2.getString(3);                                    
     
     out.println("<html>");
     out.println("<html><head><script type='text/JavaScript'>" +
             "function timedRefresh(timeoutPeriod)" +
             " {" +
             "setTimeout('location.reload(true);',timeoutPeriod);}");
out.println("</script></head> ");
     
       
      out.println("<body background=\"t7.jpg\" onload='showCompany()'>"); 
out.println("<div><div style='float:left'>");
out.println("<form action='index.html'>");
 out.println("<input type='submit' value='home'/></form></div>");
out.println("<div style='float:right'>");
 out.println("<form action='college-login.html'>");
            out.println("<input type='submit'  value='logout'/></form></div>");

     out.println("<center>");    
     
     out.println(" <br><h1> <font color=\"cyan\"> "+college_name+" </font> </h1> ");

     out.print("<br> <b> <font color=\"white\"> Affiliated to </font> <font color=\"lawngreen\"> "+university+" </font> </b>");
out.print("&nbsp &nbsp &nbsp <b> <font color=\"white\"> College-Code : </font> <font color=\"lawngreen\">"+ college_code+ "</font></b>");

   out.println("<br> <br> <br> <b><marquee text=\"red\" behavior=\"alternate\"><font size=\"3\" color=\"red\"> Placement Assistance for </font> <font color=\"cyan\" size=\"4\"> "+college_name+"</font> </marquee> </b>");

     out.println("</center>");   
out.println("<br>");
out.println("<div style='float:right;width:35%'>");
ResultSet rs5=stmt.executeQuery("select company_name from company_register");
{
         while(rs5.next())
		  {
		  String s=rs5.getString("company_name");
		  str=str+"<option value='"+s+"'>"+s+"</option>";

		  }
            out.println("<form method='post' action='ccs'>");
            out.println(" <font color=\"white\">search  company  </font><select name='company' id='company' onload='showCompany()'><option value='--select--'>--select--</option>"+str+"</select>  <input type='submit' value='search'/></form>"); 
         out.println("</div>"); 
         out.println("<div style='float:left';width:35%'>");
}
ResultSet rs7=stmt.executeQuery("select student_name from student_register where college_code='"+college_code+"'");
         while(rs7.next())
		  {
		  String s2=rs7.getString("student_name");
		  str1=str1+"<option value='"+s2+"'>"+s2+"</option>";

		  }
            out.println("<form method='post' action='css'>");
            out.println(" <font color=\"white\">search  student  </font><select name='student' id='student'><option value='--select--'>--select--</option>"+str1+"</select>  <input type='submit' value='search'/></form>"); 
         out.println("</div>"); 

    }
         
         out.println("<br><br>");
         out.println("<a href='mail2.html'><font size='4'color='CC33CC'>compose mail   .</font></a>");
 out.println("<font size='6' color='CC33CC'> <blink>updates</blink></font>"); 

 out.println("<br><br>");
 ResultSet rs6=stmt.executeQuery("select company_name,message,send_date from message where college_name='"+college_code+"'");
         out.println("<center><table border='1'>");
         while(rs6.next())
		  {
                      String company_name=rs6.getString("company_name");
                      String message=rs6.getString("message");
                      String send_date=rs6.getString("send_date");
                      out.println("<tr><td><font size='5' color='white'>");
                      out.println("<blink>");
                      out.println(company_name);out.println("</blink>");
                      out.println("</td><td><font size='4' color='white'>");
                      out.println(message);
                     out.println("</font></td>");
                     out.println("<td><form method='post'action='delete.jsp'>");
                                      out.println("<input type='hidden' name='message' value='"+message+"'/>");
                                      
                                      out.println("<input type='hidden' name='college_uname' value='"+college_uname+"'/>");
                                      out.println("<input type='hidden' name='college_pwd' value='"+college_pwd+"'/>");
                     
                     out.println("<input type='submit' value='delete'/></form></td></tr>");
		   

                    
                  }  
         out.println("</table>");
         
         ResultSet r=stmt.executeQuery("select student_id,answer,company_name from imp_clg where college_code='"+college_code+"'");
         out.println("<center><table border='2'bgcolor='white'>");
         while(r.next())
		  {
                      String company_name=r.getString("company_name");
                      String answer=r.getString("answer");
                        out.println("<tr><td><form method='post'action='del1.jsp'>");
                                     
                         out.println("<input type='hidden' name='answer' value='"+answer+"'/>");
                        out.println("<input type='hidden' name='college_uname' value='"+college_uname+"'/>");
                                      out.println("<input type='hidden' name='college_pwd' value='"+college_pwd+"'/>");
                     
                     out.println("<input type='submit' value='delete'/></form></td>");
                    
                  }  
		  ResultSet rs8=stmt.executeQuery("select company_name,question from imp_cmp where college_code='"+college_code+"'");
         out.println("<center><table border='2'bgcolor='white'>");
         while(rs8.next())
		  {
                      String company_name=rs8.getString("company_name");
                      String question=rs8.getString("question");
                        out.println("<tr><td><form method='post'action='del.jsp'>");
                                     
                         out.println("<input type='hidden' name='question' value='"+question+"'/>");
                        out.println("<input type='hidden' name='college_uname' value='"+college_uname+"'/>");
                                      out.println("<input type='hidden' name='college_pwd' value='"+college_pwd+"'/>");
                     
                     out.println("<input type='submit' value='delete'/></form></td>");
		   
                      out.println("<td><font size='4' color='black'>");
                      out.println("Reqirement from company");
                     out.println("</font></td>");
                     out.println("<td><form method='post'action='check.jsp'>");
                                     
                                      
                                      out.println("<input type='hidden' name='college_code' value='"+college_code+"'/>");
                                                 
                     out.println("<input type='submit' value='check'/></form></td></tr>");
                    
                  }  

                 
		  
 out.println("</font>");
 out.println("</table></center>");
 
     out.println("</body>");

     out.println("</html>");        

     }
 

         else

       {
   
           out.println("<html>");
     
           out.println("<body background=\"t7.jpg\">");

           out.println(" <font color=\"white\" size=\"4\"> ");
        
           out.println("<br><br> <b> Invalid Username/password </b>");
  

           out.println("<br><br> <b> <a href=\"college-login.html\"> <font color=\"cyan\"> Click </font> </a> here to reenter the Correct Username and Password </b>");

           out.println(" </font> ");
    
           out.println("</body>");

           out.println("</html>");        
  
        }

   }
 
    catch(Exception e)
       {
         response.sendError(505,e.getMessage());
         e.printStackTrace();
       }    

  }

}  

 